package com.whut.controller;

import com.whut.model.ContractCheckTask;
import com.whut.model.Measureresulttype;
import com.whut.model.Measuresystem;
import com.whut.service.MeasureService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;


/***
* 实测实量模块 Controller
* @author fuzhenjie
* @date 19.8.9 20:24
*/
@Controller
@RequestMapping("/measure")
@Scope("prototype")
public class MeasureController {

    @Resource
    private MeasureService measureService;


    /**
    * 将从前端得到的体系存入数据库，并返回新的数据
    * @author fuzhenjie
    * @date 19.8.9 20:39
    * @param measureSystem 体系
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/insertSystem")
    public Object insertSystem(Measuresystem measureSystem){
        return measureService.insertSystem(measureSystem);
    }

    /**
    * 通过前置体系的Id来获取下一级的列表
    * @author fuzhenjie
    * @date 19.8.9 20:56
    * @param preNum 前置体系Id
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getSystem")
    public Object getSystemByPreNum(int preNum){
        return measureService.getSystemByPreNum(preNum);
    }

    /**
     * 更新体系，并返回新的数据
     * @author fuzhenjie
     * @date 19.8.9 21:10
     * @param measureSystem 体系bean
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/updateSystem")
    public Object updateSystem(Measuresystem measureSystem){
        return measureService.updateSystem(measureSystem);
    }


    /**
     * 通过前置体系Id 找到实测实量体系结果详情 列表
     * @author fuzhenjie
     * @date 19.8.9 21:14
     * @param preNum 前置体系Id
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/getResultTypeList")
    public Object getResultTypeList(int preNum){
        return measureService.getResultTypeList(preNum);
    }

    /**
     * 插入新增的 结果类型bean并返回新的列表
     * @author fuzhenjie
     * @date 19.8.9 21:24
     * @param measureResultType 结果类型bean
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/insertResultType")
    public Object insertResultType(Measureresulttype measureResultType){
        return measureService.insertResultType(measureResultType);
    }

    /**
     * 更新某个结果类型 并返回更新后的数据
     * @author fuzhenjie
     * @date 19.8.9 21:29
     * @param measureResultType 结果类型bean
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/updateResultType")
    public Object updateResultType(Measureresulttype measureResultType){
        return measureService.updateResultType(measureResultType);
    }

    /**
     * 删除结果类型并返回新的结果类型列表
     * @author fuzhenjie
     * @date 19.8.13 15:54
     * @param measureresulttype 要删除的记录
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/delResultType")
    public Object delResultType(Measureresulttype measureresulttype){
        return measureService.delResultType(measureresulttype);
    }

    /**
     * 删除体系，并返回新的体系
     * @author fuzhenjie
     * @date 19.8.13 15:55
     * @param measuresystem 要删除的记录
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/delSystem")
    public Object delSystem(Measuresystem measuresystem){
        return measureService.delSystem(measuresystem);
    }

    /**
     * 通过表格的Id找出其下所有的种类信息
     * @author fuzhenjie
     * @date 19.8.18 11:28
     * @param tableId int 表格（体系第三级ID）
     * @return java.util.List<com.whut.v_model.MeasureTableDetail>
     */
    @ResponseBody
    @PostMapping("/getTableDetailByTableId")
    public Object getTableDetailByTableId(int tableId){
        return measureService.getTableDetailByTableId(tableId);
    }

    /**
     * 插入检查结果的记录
     * @author fuzhenjie
     * @date 19.8.18 12:46
     * @param jsonString String 测量点数据
     * @param cct ContractCheckTask 检查信息
     * @param userId 创建者Id
     * @return Object
     */
    @ResponseBody
    @PostMapping("/insertResultData")    
    public Object insertResultData(ContractCheckTask cct, String jsonString,int userId){
        //System.out.println(jsonString);
        return measureService.insertResultData(cct,jsonString,userId);
    }
    /**
     * 传入checkId获取检查结果
     * LYL
     * @param checkId
     */
    @ResponseBody
    @PostMapping("/getTableData")
    public Object getTableData(int checkId){
        return measureService.getTableData(checkId);
    }
    @ResponseBody
    @PostMapping("/getnewTableData")
    public Object getnewTableData(int checkId){
        return measureService.getnewTableData(checkId);
    }


    /**
    * 通过实测实量检查的一条检查表记录 来获取这张表下的各项的合格率
    *@author fuzhenjie
    *@date 19.9.23 12:17(GMT)
    *@param recordId 记录Id
    *@return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getRecordRateDetailByRecordId")
    public Object getRecordRateDetailByRecordId(int recordId){
        return measureService.getRecordRateDetail(recordId);
    }


    /**
     * 从cct表中查找出所有与包含userId的组有关的cct 时间倒序
     *@author fuzhenjie
     *@date 19.10.16 9:40(GMT)
     *@param userId int 用户Id
     *@return Object
     */
    @ResponseBody
    @PostMapping("/getCctListByUserId")
    public Object getCctListByUserId(int userId,int curPage,int pageSize){
        return measureService.getCctListByUserId(userId,curPage,pageSize);
    }


    /**
    * 通过cct的mkey来找此次检查下所有的实测实量记录
    *@author fuzhenjie
    *@date 19.10.16 18:43(GMT)
    *@param mKey int cct的主键
    *@return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getMeasureDetailByCct")
    public Object getMeasureDetailByCct(int mKey){
        return measureService.getMeasureDetailByCct(mKey);
    }
}
